package com.taku.forest.controller;

import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.http.ForestResponse;
import com.taku.forest.proxy.ForestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class TestController {


    /**
     * doc https://www.bookstack.cn/read/Forest-1.4.x-zh/1dfeb41fc0d5b35e.md
     */

    @Autowired
    ForestClient client;

    @GetMapping("get")
    public String get(){
        String url = "https://www.baidu.com";
        // 不注入上下文调用
        ForestClient instance = ForestConfiguration.configuration().createInstance(ForestClient.class);
        ForestResponse<String> res = instance.get(url,String.class);
        String content = res.getContent();
        return content;
    }

    @GetMapping("post")
    public String post(){
        String url = "https://www.baidu.com";
        // 注入上下文调用
        ForestResponse<String> res = client.get(url,String.class);
        String content = res.getContent();
        return content;
    }

}
